package guitforl.wrappers

import _root_.guitforl.traits.UpdateableWidget
import guitforl.data.readers.DataReader
import java.util.Vector
import scala.collection.JavaConversions._
import javax.swing._


/**
 * Created by IntelliJ IDEA.
 * User: Chris
 * Date: 07.07.2010
 * Time: 11:35:08 
 */

class TableWrapper(val widgetName: String, private val caption: String, private val dataSources: Seq[DataReader]) extends JPanel with UpdateableWidget {
  
  val label = new JLabel(caption, SwingConstants.CENTER)
  var table = new JTable()  
  var panel = new JScrollPane(table)

  setLayout(LayoutFactory.createTableWidgetLayout)
  add(label)
  add(panel)

  def update() = {	   
    remove(panel)
	  //TODO fix this, add multiplay files
    dataSources.apply(0).getRowsStringArray match {
      case x :: xs => table = new JTable(new Vector(asCollection(xs.map(row => new Vector[String](asCollection(row.toList))))), new Vector[String](asCollection(x.toList)))
      case _ => "Ooops!"
    }
    panel = new JScrollPane(table)
	  add(panel)
  }
}